package phyzik.monde;

import java.util.Enumeration;
import java.util.List;

import javax.media.j3d.Behavior;
import javax.media.j3d.WakeupOnElapsedTime;

import phyzik.solides.PhysiqueSolide;

public class Loop extends Behavior {
	private static final int DELAI = 100;
	protected List<PhysiqueSolide> solides;

	protected WakeupOnElapsedTime reveil;

	public Loop(List<PhysiqueSolide> solides) {
		this.solides = solides;
		reveil = new WakeupOnElapsedTime(DELAI);
	}

	@Override
	public void initialize() {
		commencer();
		wakeupOn(reveil);
	}

	@Override
	@SuppressWarnings("unchecked")
	public void processStimulus(Enumeration enu) {
		tournerMoteur(0.1f);
		wakeupOn(reveil);
	}

	public void commencer() {
		for (PhysiqueSolide s : solides) {
			s.mettreAzero();
			s.calculsDerives();
		}
	}

	public void tournerMoteur(float dt) {
		for (PhysiqueSolide s : solides) {
			s.integration(dt);
		}
	}
}
